<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->

<?php
include("../models/entities/class.AccountEntity.php");
@session_start();
if(isset($_SESSION["Username"]))
{
include("../models/webconfig.php");
include("../models/class.connection.php");
include("../models/repositories/class.AccountRepository.php");
include("../models/entities/class.GroupEntity.php");

include("../models/repositories/class.GroupAuthorityRepository.php");
if(isset($_SESSION['Account'])){
    $groupAuthorityRepository = new GroupAuthorityRepository();
    $account = $_SESSION['Account'];
    if(!$groupAuthorityRepository->CheckExistGroupAuthority($account->GroupID_i, 1))
        header("location:NoAccess.php");
}
else
{
    header("location:NoAccess.php");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Thêm Tài Khoản</title>
        <link href="../content/Layout.css" rel="stylesheet" type="text/css" media="screen"/>
        <script type="text/javascript" src="../scripts/jquery-1.4.2.min.js"></script>
        <script type="text/javascript" src="../scripts/adminaccount.js"></script>
    </head>
    <body>
        <div id="format">
            <div id="wrapper" >
                <!--Ph?n main menu-->

<?php
include("../includes/backend_mainnav.php");

$accres = new AccountRepository();
?>
                <center>
                    <div class="HeaderInsert"><h1>Thêm Tài Khoản</h1></div>
                    <div class="ContentInsert">

                        <form action="../views/InsertAccount.php" method="post" >
                            <table>
                                <tr>
                                    <td style="text-align: right">Tên Tài Khoản: </td>
                                    <td style="text-align: left;width: 270px;">
                                        <input type="text" style="width: 200px" name="inUsername" id="inUsername" onchange="checkInfoInsert()" >
                                         <label id="alertUsername" style="color:red;">(*)</label>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align: right">Mật Khẩu:</td>
                                    <td style="text-align: left;width: 270px;">
                                        <input type="password" style="width: 200px" name="inPassword" id="inPassword" onchange="checkInfoInsert()">
                                        <label id="alertPassword" style="color:red;">(*)</label>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align: right">Email:</td>
                                    <td style="text-align: left;width: 270px;"><input type="text" style="width: 200px" name="inEmail" id="inEmail" onchange="checkInfoInsert()">
                                    <label id="alertEmail" style="color:red;">(*)</label>
                                    </td>
                                    
                                </tr>
                                <tr>
                                    <td style="text-align: right">Group:</td>
                                    <td style="text-align: left;width: 270px;"><select name="inGroup">
<?php
$group = $accres->GetAllGroup();
foreach ($group as $g) {
?>
                                            <option value="<?php echo $g->ID_i ?>"><?php echo $g->Name_s; ?></option>
                                            <?php
                                        }
                                            ?>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align: right">Yahoo_ID</td>
                                    <td style="text-align: left;width: 270px;">
                                        <input type="text" style="width: 200px" name="inYahooid" id="inYahooid" onchange="checkInfoInsert()">
                                     <label id="alertYahooid" style="color:red;">(*)</label>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align: right">Hỗ Trợ</td>
                                    <td style="text-align: left;width: 270px;"><input type="checkbox" name="inHoTro"></td>
                                </tr>
                                <?php
                                        if (isset($_POST["inUsername"])) {
                                            if ($_POST["inUsername"] != "" && $_POST["inPassword"] != "" && $_POST["inEmail"] != "" && $_POST["inYahooid"]) {
                                                if(isset($_POST["inHoTro"])){
                                                    $b=1;
                                                }
                                                else{
                                                    $b=0;
                                                }
                                                if(!$accres->CheckAccount($_POST["inUsername"])){
                                                    $result=$accres->Insert($_POST["inUsername"],md5($_POST["inPassword"]), $_POST["inEmail"], $_POST["inGroup"], $_POST["inYahooid"],$b );
                                                    if($result){
                                                        echo "Thêm thành công";
                                                    }
                                                    else{
                                                        echo"Có lỗi";
                                                    }
                                                }
                                                else{
                                                    echo "Tài khoản đã tồn tại! ";
                                                }

                                            } else {
                                                echo "Nhập đầy đủ thông tin";
                                            }
                                        }
?>
                                <tr>
                                    <td colspan="2" style="text-align: center" id="btnsubmit">
<!--                                        <input type="submit" name ="inSubmit" value="Thêm Tài Khoản">-->
                                    </td>
                                </tr>
                            </table>
                        </form>
                    </div>
                </center>
            </div>
        </div>
<?php
                                        include("../includes/backend_footer.php");
?>
    </body>
</html>
<?php
}
else
{
    header("location:../views/Admin_login.php?logout=TRUE");
}
?>
